package org.czl.leetCode1;

public class L968 {
    int ans = 0;
    public int minCameraCover(TreeNode root) {
        if(dfs(root) == 0) ans++;
        return ans;
    }

    int dfs(TreeNode root){
        if(root == null){
            return 1; //默认null是被覆盖的
        }
        int left = dfs(root.left);
        int right = dfs(root.right);
        if(left == 0 || right == 0){
            ans++;
            return 2; //当前节点必须放摄像头
        }
        if(left == 1 && right == 1){
            return 0;
        }
        return 1;
    }
}
